var RPC = {};
var edxUrl = "http://localhost:44455/Rpc/api.min.js";
function loadScript(url, callback) {

	var script = document.createElement("script")
	script.type = "text/javascript";

	if (script.readyState) {  //IE
		script.onreadystatechange = function () {
			if (script.readyState == "loaded" ||
					script.readyState == "complete") {
				script.onreadystatechange = null;
				callback();
			}
		};
	} else {  //Others
		script.onload = function () {
			callback();
		};
	}

	script.src = url;
	document.getElementsByTagName("head")[0].appendChild(script);
}
RPC.Target = {};
RPC.Target.OnPost = function (message, origin) {
};
RPC.Target.OnError = function (message, origin) {
};

RPC.Target.Init = function () {
	loadScript(edxUrl, function () {
		var transport = new easyXDM.Rpc({
			swf: "http://localhost:44455/Rpc/easyxdm.swf",
			remote: "http://localhost:44455/Proxy/Index",
			remoteHelper: "http://localhost:44455/Rpc/name.html"
		},
		{
			local: {
				returnResponse: function (response) {
					RPC.Target.OnPost(response, "null");
				},
				returnError: function (Xhr,st,Er) {
					RPC.Target.OnError(Er, "null");
				}
			},
			remote: {
				Post: {},
				Get: {},
				noOp: {}
			}

		}
		);
		RPC.Target.Socket = transport;
	});
};

RPC.Target.Post = function (data, success, error) {
	RPC.Target.OnPost = function (message, origin) {
		if (success) {
			success(message, origin);
		}
	};
	RPC.Target.Socket.Post(data);
};

//Call
RPC.Target.Init();

		   
